home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / misc / wvware-mos.lha / bin / wvPDF < prev    next >
Text File  |  2002-05-07  |  8KB  |  349 lines

  1. #!/bin/sh
  2.  
  3. wv_script_name="$0"
  4.  
  5. which latex >/dev/null 2>&1
  6. if [ ${?} -ne "0" ]; then
  7.   echo "Could not find required program 'latex'"
  8.   exit 1
  9. fi
  10.  
  11. which dvips >/dev/null 2>&1
  12. if [ ${?} -ne "0" ]; then
  13.   echo "Could not find required program 'dvips'"
  14.   exit 1
  15. fi
  16.  
  17. distiller="none"
  18. which distill >/dev/null 2>&1
  19. if [ ${?} -ne "0" ]; then
  20.   which ps2pdf >/dev/null 2>&1
  21.   if [ ${?} -ne "0" ]; then
  22.     distiller="none"
  23.   else
  24.     distiller="ps2pdf"
  25.   fi
  26. else
  27.   distiller="distill"
  28. fi
  29.  
  30. if test "$distiller" = "none"; then
  31.   echo "Could not find required program(s) 'distill' or 'ps2pdf'"
  32.   exit 1
  33. fi
  34.  
  35. prefix=/gg
  36. exec_prefix=
  37. datadir=
  38. t_dir=.
  39.  
  40. wv_opts=
  41. i_file=
  42. o_file=
  43. print_help=no
  44.  
  45. while test $# -gt 0; do
  46.   case "$1" in
  47.   -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  48.   *) optarg= ;;
  49.   esac
  50.  
  51.   case $1 in
  52.     --prefix=*)
  53.       prefix=$optarg
  54.       ;;
  55.     --exec-prefix=*)
  56.       exec_prefix=$optarg
  57.       ;;
  58.     --datadir=*)
  59.       datadir=$optarg
  60.       ;;
  61.     --targetdir=*)
  62.       t_dir=$optarg
  63.       ;;
  64.     --charset=* | --password=*)
  65.       wv_opts="$wv_opts $1"
  66.       ;;
  67.     -v | --version)
  68.       echo 0.7.2
  69.       exit 0
  70.       ;;
  71.     -\? | -h | --help)
  72.       cat << EOF
  73. Usage: $wv_script_name [OPTIONS] <input-file> <output-file>
  74. Options:
  75.       --prefix=<DIR>        Set prefix (default is /gg)
  76.       --exec-prefix=<DIR>   Set exec_prefix (default is ${prefix})
  77.       --datadir=<DIR>       Set datadir (default is ${prefix}/share)
  78.       --targetdir=<DIR>     Target directory (target is <DIR>/<output-file>)
  79.       --charset=<charset>   Specify an iconv charset encoding
  80.       --password=<password> Specify password for encrypted
  81.   -v, --version             Print version info and exit
  82.  
  83. Authors:
  84.   Dom Lachowicz (dominicl@seas.upenn.edu)
  85.   Caolan McNamara (original author)
  86. Visit http://www.wvware.com/
  87. EOF
  88.       exit 0
  89.       ;;
  90.     -?*)
  91.       echo "Option '$1' not recognized."
  92.       exit 1
  93.       ;;
  94.     *)
  95.       if test "x$i_file" = "x"; then
  96.         i_file=$1
  97.       elif test "x$o_file" = "x"; then
  98.         o_file=$1
  99.       else
  100.         echo "Option '$1' not recognized."
  101.         exit 1
  102.       fi
  103.       ;;
  104.   esac
  105.   shift
  106. done
  107.  
  108. if test "x$i_file" = "x-"; then
  109.   echo "error: cannot specify '-' as input"
  110.   exit 1
  111. fi
  112. if test -r "$i_file"; then
  113.   okay=yes
  114. else
  115.   echo "error: '$i_file' unreadable"
  116.   exit 1
  117. fi
  118.  
  119. if test "x$o_file" = "x"; then
  120.   echo "Usage: $1 [OPTIONS] <input-file> <output-file>"
  121.   exit 1
  122. fi
  123. if test "x$i_file" = "x-"; then
  124.   echo "error: cannot specify '-' as output"
  125.   exit 1
  126. fi
  127. name=`basename "$o_file"`
  128. if test "x$o_file" != "x$name"; then
  129.   echo "error: use '--targetdir' for writing in another directory"
  130.   exit 1
  131. fi
  132. name=`basename "$o_file" | sed "s/ /_/g"`
  133. name=`echo $name | sed 's/\.[^\.]*$//'`
  134.  
  135. if test "x$exec_prefix" = "x"; then
  136.   exec_prefix=${prefix}
  137. fi
  138. wv_exec="$exec_prefix/bin/wvWare"
  139. if test -x "$wv_exec"; then
  140.   okay=yes
  141. else
  142.   wv_version=`wvWare -v 2>&1 | cut -f 2 -d " "`
  143.   if test "x$wv_version" = "x0.7.2"; then
  144.     wv_exec="wvWare"
  145.   else
  146.     echo "error: no executable at '$wv_exec' or in path"
  147.     exit 1
  148.   fi
  149. fi
  150.  
  151. if test "x$datadir" = "x"; then
  152.   datadir=${prefix}/share
  153. fi
  154. xmlcfg="$datadir/wv/wvLaTeX.xml"
  155. if test -r "$xmlcfg"; then
  156.   okay=yes
  157. else
  158.   echo "error: '$xmlcfg' unreadable"
  159.   exit 1
  160. fi
  161.  
  162. if test -d "$t_dir"; then
  163.   if test -w "$t_dir"; then
  164.     okay=yes
  165.   else
  166.     echo "error: '$t_dir' is not writable"
  167.     exit 1
  168.   fi
  169. else
  170.   echo "error: '$t_dir' is not a directory"
  171.   exit 1
  172. fi
  173.  
  174. # auto_wmf=`"$wv_exec" --auto-eps=wmf`
  175. # auto_emf=`"$wv_exec" --auto-eps=emf`
  176. # auto_png=`"$wv_exec" --auto-eps=png`
  177. # auto_jpg=`"$wv_exec" --auto-eps=jpg`
  178. # auto_pict=`"$wv_exec" --auto-eps=pict`
  179.  
  180. im_chk=`convert --help 2>&1 | grep -v ImageMagick`
  181. if test "x$im_chk" = "x"; then
  182.   im_chk="no"
  183.   s_img=""
  184. else
  185.   im_chk="yes"
  186. # if we have ImageMagick's convert, then use that to convert PNG, JPEG & PICT
  187. # to EPS. Therefore, need to suppress wvWare's desire to convert these:
  188.   s_img="png,jpg,pict"
  189. fi
  190.  
  191. "$wv_exec" $wv_opts -x "$xmlcfg" -d "$t_dir" -b "$name" "$i_file" -s "$s_img" > "$t_dir"/"$name".tex
  192.  
  193. cd "$t_dir"
  194.  
  195. echo
  196. echo 'Current directory: '`pwd`
  197.  
  198. # First, convert any images
  199.  
  200. i_okay=yes
  201.  
  202. for i_name in "$name"*.wmf; do
  203.   if test -r "$i_name"; then
  204.     e_name=`echo "$i_name" | sed 's/wmf$/eps/'`
  205.     if test -r "$e_name"; then
  206.       echo '"'$e_name'"' exists - skipping...
  207.     else
  208.       if test "$im_chk" = "yes"; then
  209.         convert "$i_name" "$e_name"
  210.         if test -r "$e_name"; then
  211.           echo created '"'$e_name'"'
  212.         else
  213.           echo '"'$i_name'"': conversion failed
  214.           i_okay=no
  215.         fi
  216.       else
  217.         echo unable to convert '"'$i_name'"' '(no converter)'
  218.         i_okay=no
  219.       fi
  220.     fi
  221.   fi
  222. done
  223.  
  224. for i_name in "$name"*.emf; do
  225.   if test -r "$i_name"; then
  226.     e_name=`echo "$i_name" | sed 's/emf$/eps/'`
  227.     if test -r "$e_name"; then
  228.       echo '"'$e_name'"' exists - skipping...
  229.     else
  230.       echo unable to convert '"'$i_name'"' '(no converter)'
  231.       i_okay=no
  232.     fi
  233.   fi
  234. done
  235.  
  236. for i_name in "$name"*.png; do
  237.   if test -r "$i_name"; then
  238.     e_name=`echo "$i_name" | sed 's/png$/eps/'`
  239.     if test -r "$e_name"; then
  240.       echo '"'$e_name'"' exists - skipping...
  241.     else
  242.       if test "$im_chk" = "yes"; then
  243.         convert "$i_name" "$e_name"
  244.         if test -r "$e_name"; then
  245.           echo created '"'$e_name'"'
  246.         else
  247.           echo '"'$i_name'"': conversion failed
  248.           i_okay=no
  249.         fi
  250.       else
  251.         echo unable to convert '"'$i_name'"' '(no converter)'
  252.         i_okay=no
  253.       fi
  254.     fi
  255.   fi
  256. done
  257.  
  258. for i_name in "$name"*.jpg; do
  259.   if test -r "$i_name"; then
  260.     e_name=`echo "$i_name" | sed 's/jpg$/eps/'`
  261.     if test -r "$e_name"; then
  262.       echo '"'$e_name'"' exists - skipping...
  263.     else
  264.       if test "$im_chk" = "yes"; then
  265.         convert "$i_name" "$e_name"
  266.         if test -r "$e_name"; then
  267.           echo created '"'$e_name'"'
  268.         else
  269.           echo '"'$i_name'"': conversion failed
  270.           i_okay=no
  271.         fi
  272.       else
  273.         echo unable to convert '"'$i_name'"' '(no converter)'
  274.         i_okay=no
  275.       fi
  276.     fi
  277.   fi
  278. done
  279.  
  280. for i_name in "$name"*.pict; do
  281.   if test -r "$i_name"; then
  282.     e_name=`echo "$i_name" | sed 's/pict$/eps/'`
  283.     if test -r "$e_name"; then
  284.       echo '"'$e_name'"' exists - skipping...
  285.     else
  286.       if test "$im_chk" = "yes"; then
  287.         convert "$i_name" "$e_name"
  288.         if test -r "$e_name"; then
  289.           echo created '"'$e_name'"'
  290.         else
  291.           echo '"'$i_name'"': conversion failed
  292.           i_okay=no
  293.         fi
  294.       else
  295.         echo unable to convert '"'$i_name'"' '(no converter)'
  296.         i_okay=no
  297.       fi
  298.     fi
  299.   fi
  300. done
  301.  
  302. if test "$i_okay" = "no"; then
  303.   echo 'WARNING: Failed to convert one or more images to EPS'
  304. fi
  305.  
  306. # "$name".tex is the LaTeX file
  307. # use latex to convert this to DVI
  308.  
  309. latex --interaction=batchmode "$name".tex >/dev/null 2>&1
  310.  
  311. # check latex exit status and comment or clean up
  312. if [ ${?} -ne "0" ]; then
  313.     echo "Some problem running latex."
  314.     echo "Check for Errors in $name.log"
  315.     echo "Continuing..."
  316. else
  317.     rm -f "$name".aux "$name".log "$name".tex
  318. fi
  319.  
  320. # latex replaces the "tex" extension with a "dvi" extension
  321. if [ ! -f "$name".dvi ]; then
  322.     echo "Conversion into dvi failed"
  323.     exit 1
  324. fi
  325.  
  326. dvips -o "$name".ps "$name".dvi >/dev/null 2>&1
  327. if [ ${?} -ne "0" ]; then
  328.     echo "Could not convert into Postscript"
  329.     exit 1
  330. fi
  331.  
  332. #clean up
  333. rm -f "$name".dvi
  334.  
  335. if test "$distiller" = "distill"; then
  336.   distill "$name".ps >/dev/null 2>&1
  337. else
  338.   ps2pdf "$name".ps "$name".ps.pdf >/dev/null 2>&1
  339. fi
  340. if [ ${?} -ne "0" ]; then
  341.     echo "Could not convert into PDF"
  342.     exit 1
  343. fi
  344.  
  345. cp -f "$name".ps.pdf "$o_file"
  346.  
  347. #clean up
  348. rm -f "$name".ps "$name".ps.log "$name".ps.pdf
  349.